<%@ page import="java.util.List" %>
<%@ page import="com.huazi.www.doctor.hu.entity.Drug" %>
<%@ page import="com.huazi.www.doctor.hu.service.impl.DoctorServiceImpl" %>
<%@ page import="com.huazi.www.doctor.hu.entity.Medicine" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%--
  Created by IntelliJ IDEA.
  User: 29513
  Date: 2021/5/7
  Time: 9:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><%
    //获取项目的根路径
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
    <title>Title</title>
    <meta charset="utf-8">
    <title>Layui</title>
    <link rel="stylesheet" href="<%=basePath%>swee/sweetalert.css">
    <script src="<%=basePath%>swee/sweetalert-dev.js"></script>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css" media="all">
    <script src="<%=basePath%>layui-v2.6.5/layui/layui.js" type="text/javascript"></script>

    <script src="<%=basePath%>doctor/js/jquery-1.12.4.js" type="text/javascript" ></script>

<%--    <script src="<%=basePath%>layui-v2.6.5/layui/layui.js"></script>--%>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>layui-v2.6.5/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="<%=basePath%>doctor/css/MedicineSelect.css">
    <style type="text/css">
        #back{
            border:1px solid #0bc9be;
            width: 100px;
            height: 40px;
            display: inline-block;
            background-color: white;
            position: relative;
            right: -1250px;
        }
    </style>
</head>
<body>





<div id="big">
    <button type="button" onclick="window.history.back()" id="back">返回</button>
<table class="layui-table" lay-skin="line">
    <colgroup>
        <col width="150">
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>编号</th>
        <th>病人编号</th>
        <th>病人姓名</th>
        <th>医生编号</th>
        <th>问诊时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tbody">

        <c:forEach items="${pat.list}" var="pat">
            <tr >
                <td>${pat.getId()}</td>
                <td>${pat.getPatientId()}</td>
                <td>${pat.getPatientName()}</td>
                <td>${pat.getDoctorid()}</td>
                <td>${pat.getTime()}</td>
                <td>问诊中</td>
                <td>
                    <div class="layui-btn-container">
                    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm ct" onclick="showCt(${pat.getPatientId()})">查看CT结果</button>
                    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm bl" onclick="showHis(${pat.getPatientId()})">查看以往病例</button>
                    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="kaiyao">开药</button>
                    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="cheneck">去检查</button>
                    </div>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>
</div>
<div style="position: absolute;left: 580px">
<c:if test="${requestScope.pat.currentPage>1}">
    <a href="<%=basePath%>DoctorServlet?currentPage=${requestScope.pat.currentPage-1}" >
        <button class="layui-btn layui-btn-primary layui-border-green">上一页</button>
    </a>
</c:if>
${pat.getCurrentPage()}/${pat.getTotalPage()}
<c:if test="${requestScope.pat.currentPage<pat.getTotalPage()}">
    <a href="<%=basePath%>DoctorServlet?currentPage=${requestScope.pat.currentPage+1}">
        <button class="layui-btn layui-btn-primary layui-border-green">下一页</button>
    </a>
</c:if>
</div>
<%--CT盒子--%>
<div id="ctDiv" class="layui-bg-gray" style="padding: 30px;width: 950px;height: 450px;position: absolute;top: 50px;left: 150px;overflow: auto">
    <div class="layui-btn-container" style="position: absolute;top: 0;left: 905px" id="CtClose">
        <button type="button" class="layui-btn"><i class="layui-icon">X</i></button>
    </div>
    <div class="layui-row layui-col-space15">
<%--        <div class="layui-col-md6">--%>
<%--            <div class="layui-panel">--%>
                <div style="padding: 50px 30px;">
                    <table class="layui-table" lay-skin="line">
                        <colgroup>
                            <col width="150">
                            <col width="150">
                            <col width="200">
                            <col>
                        </colgroup>
                        <thead style="overflow: auto">
                        <tr>
                            <th>编号</th>
                            <th>病人编号</th>
                            <th>病人姓名</th>
                            <th>时间</th>
                            <th>检查项目</th>
                            <th>检查结果</th>
                            <th>医生编号</th>
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                </div>

    </div>
</div>
<%--病例盒子--%>
<div id="DisDiv" class="layui-bg-gray" style="padding: 30px;width: 950px;height: 450px;position: absolute;top: 50px;left: 150px;display: none;overflow: auto">
    <div class="layui-btn-container" style="position: absolute;top: 0;left: 905px" id="DisClose">
        <button type="button" class="layui-btn"><i class="layui-icon">X</i></button>
    </div>
    <div class="layui-row layui-col-space15">
        <%--        <div class="layui-col-md6">--%>
        <%--            <div class="layui-panel">--%>
        <div style="padding: 50px 30px;">
            <table class="layui-table" lay-skin="line">
                <colgroup>
                    <col width="150">
                    <col width="150">
                    <col width="200">
                    <col>
                </colgroup>
                <thead style="overflow: auto">
                <tr>
                    <th>病例</th>
                    <th>患病时间</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
        <%--            </div>--%>
        <%--        </div>--%>
    </div>
</div>

<%--开药盒子--%>
<div class="yaodand"></div>
    <div class="yaodan">
        <h1 style="color:#009f95;">华子医院</h1>
        <h3 style="color:#009f95;">门诊处开药</h3>
        <br>
        <form action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">诊断号:</label>
                    <div class="layui-input-inline">
                        <input type="tel" name=""  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">姓名:</label>
                    <div class="layui-input-inline">
                        <input type="text" name=""  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">医生:</label>
                    <div class="layui-input-inline">
                        <input type="tel" name=""  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="myclock"  autocomplete="off" class="layui-input" style="border: none;border-bottom: 1px solid #009f95;" readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">诊断结果:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="" id="bingli"  autocomplete="off" class="layui-input" style=" width:300px ;border: none;border-bottom: 1px solid #009f95;">
                    </div>
                </div>
            </div>
        </form>


<div id="wz" style="background-color: white">
        <div id="test7" class="demo-transfer" style="margin-left: 20px" class="wezhi"></div>
        <div class="layui-btn-container" style="margin-left: 20px" class="wezhi">
            <button type="button" class="layui-btn" lay-demotransferactive="getData" id="suoding">确认药品</button>
            <button type="button" class="layui-btn" lay-demotransferactive="reload" id="sousuo">搜索药品</button>

        </div>
        </div>

        <button type="button" class="layui-btn"  id="drugok">确认开药</button>
        <button type="button" class="layui-btn"  id="drugno">取消</button>
        <div class="sum">
            <p class="drugdan" style="font-size: 20px">
                药品号<span STYLE="margin-left: 80px;"></span>
                药品名<span STYLE="margin-left: 145px;"></span>
                数量<span STYLE="margin-left: 115px;"></span>
                医嘱</p>
        </div>

    </div>
    <div class="bccheckqueue"></div>
    <div class="checkqueue" >
        <span style=" color:#009f95;margin-top: 10px"><h2 >华子医院</h2>
        <h3 style="margin-left: 10px">检查项目</h3>
        </span>

        <form class="layui-form" action="" style="background-color: white;">
            <div class="layui-inline">
                <label class="layui-form-label"   >诊断号:</label>
                <div class="layui-input-inline">
                    <input type="tel" name=""  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">姓名:</label>
                <div class="layui-input-inline">
                    <input type="text" name=""  autocomplete="off" class="layui-input">
                </div>
            </div>
            <br><br>

            <label class="layui-form-label">检查项目</label>
            <div class="layui-input-inline">
                <select name="modules" lay-verify="required" lay-search="">
                    <option value="0">CT</option>
                    <option value="1">和磁共振</option>
                    <option value="2">B超</option>
                    <option value="3">心电图</option>
                    <option value="4">常规检查</option>
                </select>
            </div>
        </form>
        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="checkok">确认</button>
        <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="checkno">取消</button>


    </div>

</div>






<script type="text/javascript">
    var arr=new Array()//id
    var arrname=new Array()//药名
    <%
     DoctorServiceImpl service=new DoctorServiceImpl();
     List<Drug> li=service.list();
    %>

    var getDataa=null
    layui.use(['transfer', 'layer', 'util'], function(){
        var $ = layui.$
            ,transfer = layui.transfer
            ,layer = layui.layer
            ,util = layui.util;


        //获得数据库所有药的数据

        var data1 = [
<%
for (int i=0;i<li.size();i++){
%>
            {"value":'<%=li.get(i).getDrugid()%>' , "title": '<%=li.get(i).getDrugname()%>'},
           <%}%>
        ]
        //基础效果
        transfer.render({
            elem: '#test1'
            ,data: data1
        })
        //定义标题及数据源
        transfer.render({
            elem: '#test2'
            ,title: ['候选文人', '获奖文人']  //自定义标题
            ,data: data1
            //,width: 150 //定义宽度
            ,height: 210 //定义高度
        })
        //显示搜索框
        // transfer.render({
        //     elem: '#test4'
        //     ,data: data1
        //     ,title: ['文本墨客', '获奖文人']
        //     ,showSearch: true
        // })

        //数据格式解析
        transfer.render({
            elem: '#test5'
            ,parseData: function(res){
                return {
                    "value": res.id //数据值
                    ,"title": res.name //数据标题
                    ,"disabled": res.disabled  //是否禁用
                    ,"checked": res.checked //是否选中
                }
            }
            ,data: [
                {"id": "1", "name": "李白"}
                ,{"id": "2", "name": "杜甫"}
                ,{"id": "3", "name": "贤心"}
            ]
            ,height: 150
        })

        //穿梭时的回调
        // transfer.render({
        //     elem: '#test6'
        //     ,data: data1
        //     ,onchange: function(obj, index){
        //         var arr = ['左边', '右边'];
        //         layer.alert('来自 <strong>'+ arr[index] + '</strong> 的数据：'+ JSON.stringify(obj)); //获得被穿梭时的数据
        //     }
        // })

        //实例调用
        transfer.render({
            elem: '#test7'
            ,data: data1
            ,id: 'key123' //定义唯一索引
        })
        //批量办法定事件
        util.event('lay-demoTransferActive', {
            getData: function(othis){
                getDataa = transfer.getData('key123'); //获取右侧数据
                $(function (){

                        var count=0;
                        for(var i in getDataa) {

                            count++;
                        }

                        for(i=0;i<count;i++) {
                            $(".drugdan").after("<p class="+"xunhuan"+"><span>"+
                                getDataa[i].value+"</span><span>"+getDataa[i].title+"</span><span></span><input type='text' value='5'>盒"+"" +
                                " <input type='text' id='yizhu' value='每日3片' style='margin-left: 80px;border: none;border-bottom: 1px solid #e3e2e2 '  ></p>")
                        }

                })
                // layer.alert(JSON.stringify(getDataa));
            }
            ,reload:function(){
                //实例重载
                transfer.reload('key123', {
                    title: ['药库', '开药']
                    ,value: []
                    ,showSearch: true
                })
            }
        });


    });
</script>
<script type="text/javascript">








    $("#ctDiv").hide();//隐藏CT结果
    $("#DisDiv").hide();//隐藏以往病例
    $("#open").hide();//隐藏开药盒子

    $(function (){
        $(".ct").click(function (){
            $(this).addClass("layui-btn layui-btn-disabled");
            $("#big").css({"opacity":"0.2","background-color":"#a9a9a9"});
        })
        $(".bl").click(function () {
            $(this).addClass("layui-btn layui-btn-disabled");
            $("#big").css({"opacity":"0.2"});
        })
        $("#CtClose").click(function () {
            $("#ctDiv").hide();
            $(".ct").removeClass("layui-btn-disabled");
            $("#ctDiv tbody").find("tr").remove();
            $("#big").css({"opacity":"1"});
        })
        $("#DisClose").click(function () {
            $("#DisDiv").hide();
            $(".bl").removeClass("layui-btn-disabled");
            $("#DisDiv tbody").find("tr").remove();
            $("#big").css({"opacity":"1"});
        })

        //开药
        // $("#kaiyao").click(function (){
        //     $(".yaodand").show()
        // })
        $("#tbody").on("click","#kaiyao",function (){
            $(".yaodand").show()
            $(".yaodan").show()
            $(".drugdan~p").remove();

            // 获得所有开药框所有的节点
            for (var i=0,j=1;i<4;i++,j++)
            {

                $(".layui-form-item input:eq("+i+")").val($(this).parent().parent().parent().children("td:eq("+j+")").text())
            }
            $(".layui-form-item input:eq(3)").val("")

        })
        // 确认开药
        $("#drugok").click(function (){
            //获取 诊断号
            var id= $(".layui-form-item input:eq(0)").val()
            //获取 姓名
            var name= $(".layui-form-item input:eq(1)").val()
            //获取 医生
            var doctorid= $(".layui-form-item input:eq(2)").val()
            //获取 时间
            var time=$(".layui-form-item input:eq(3)").val()
            //得到药品长度
            var len=$(".drugdan~p").length;



            var drugid=new Array();
            var drugsum=new Array();
            var drugtype=new Array();
            //获取节点的药品 数量 医嘱等信息
            var arrlist=$(".drugdan~p")

            for (var i=0;i<len;i++)
            {
                drugid[i]=$(arrlist[i]).children("span:eq(0)").text()
                drugsum[i]=$(arrlist[i]).children("input:eq(0)").val()
                drugtype[i]=$(arrlist[i]).children("input:eq(1)").val()
            }
            let strid = drugid.join("-");
            let strsum=drugsum.join("-");
            let strtype=drugtype.join("-");



            $.ajax({
                url:"http://localhost:8080/com/DoctorServlet",
                type:"post",
                data:{
                    czf:"kaiyao",
                    id:id,
                    name:name,
                    doctorid:doctorid,
                    time:time,
                     drugid:strid,
                    drugsum:strsum,
                    drugtype:strtype,
                    bingli:$("#bingli").val()
                },
                dateType:"json",
                success:function (data){
                    swal("开药成功", "","success");
                    window.location.replace("http://localhost:8080/com/DoctorServlet");
                }
            })
        })
        $("#drugno").click(function (){
            $(".yaodand").hide()
            $(".yaodan").hide()
            $(".drugdan~p").remove();
        })

        //检查
        $("#tbody").on("click","#cheneck", function (){
            $(".checkqueue,.bccheckqueue").show()
            $(".checkqueue input:eq(0)").val($(this).parent().parent().parent().children("td:eq(1)").text())
            $(".checkqueue input:eq(1)").val($(this).parent().parent().parent().children("td:eq(2)").text())
        })
        //确定检查
        $("#checkok").click(function (){

            $.ajax({
                url:"http://localhost:8080/com/DoctorServlet",//请求路径
                type:"post",//请求方式
                data:{
                    czf:"ctqueue",
                    id:$(".checkqueue input:eq(0)").val()
                },//请求参数
                dataType:"json",//数据格式
                success:function (data){
                    if(data==false){

                    swal("检查单已开，通知患者去检查")
                        $(".checkqueue,.bccheckqueue").hide()
                        window.location.replace("http://localhost:8080/com/DoctorServlet");
                    }else{
                     swal("请不要重复开检查单")
                        $(".checkqueue,.bccheckqueue").hide()
                    }
                }
            })
        })

        //关闭
        $("#checkno").click(function (){
            $(".checkqueue,.bccheckqueue").hide()
        })





    })




    function dispttime()
    {
        var today=new Date();
        var yearr=today.getFullYear();
        var moth=today.getMonth();
        var ri=today.getDate();
        var hh=today.getHours()
        var mm=today.getMinutes()
        var ss=today.getSeconds();
        var sh="";
        if(hh<12)
        {
            sh="AM"
        }
        else
        {
            sh="PM"
        }
        if(hh>12)
        {
            hh=hh-12
        }

        document.getElementById("myclock").value=yearr+"/"+(moth+1)+"/"+ri+"/"+hh+":"+mm+":"+ss
9
    }
    setInterval("dispttime()",1000)

    function showCt(no){
        let ctNo=no;//获取病人编号,查询ct结果
        // alert(ctNo);
        $.ajax({
            url:"DoctorServlet",//请求路径
            type:"get",//请求方式
            data:{
                ctNo:ctNo,
                czf:"selCt"
            },//请求参数
            dataType:"json",//数据格式
            success:function (ctList){
                if(ctList==null){
                    swal("该病人没有CT记录");
                    $(".ct").removeClass("layui-btn-disabled");
                    $("#big").css({"opacity":"1"});
                }else {
                    $("#ctDiv").show();
                    for (let i = 0; i < ctList.length; i++) {
                        let tr="<tr> <td>"+ctList[i].id+"</td><td>"+ctList[i].cdiagnoseNo+"</td><td>"+ctList[i].name+"</td><td>"+ctList[i].time+"</td><td>"+ctList[i].inspectionItem+"</td><td>"+ctList[i].diagnose+"</td><td>"+ctList[i].doctorid+"</td></tr>";
                        // alert(tr);
                        $("#ctDiv tbody").append(tr);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(0)").text(ctList[i].id);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(1)").text(ctList[i].cdiagnoseNo);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(2)").text(ctList[i].name);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(3)").text(ctList[i].time);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(4)").text(ctList[i].inspectionItem);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(5)").text(ctList[i].diagnose);
                        // $("#ctDiv tbody").find("tr:eq(i) td:eq(6)").text(ctList[i].doctorid);
                    }
                }
            }
        })
    }
    function showHis(no){
        let ctNo=no;//获取病人编号,查询ct结果
        // alert(ctNo);
        $.ajax({
            url:"DoctorServlet",//请求路径
            type:"get",//请求方式
            data:{
                ctNo:ctNo,
                czf:"selDis"
            },//请求参数
            dataType:"json",//数据格式
            success:function (DiList){
                if(DiList==null){
                    swal("该病人没有以往病例");
                    $(".bl").removeClass("layui-btn-disabled");
                    $("#big").css({"opacity":"1"});
                }else {
                    $("#DisDiv").show();
                    for (let i = 0; i < DiList.length; i++) {
                        let tr="<tr> <td>"+DiList[i].usertype+"</td><td>"+DiList[i].time+"</td></tr>";
                        // alert(tr);
                        $("#DisDiv tbody").append(tr);
                    }
                }
            }
        })
    }


</script>
</body>
</html>
